﻿using System;
using System.Collections.Generic;
using Eamon.MeituanDotnetSDK.api.common.request;
using Eamon.MeituanDotnetSDK.api.oauth.@enum;
using Eamon.MeituanDotnetSDK.utils;

namespace Eamon.MeituanDotnetSDK.api.oauth.entity
{
    [Serializable]
    public class DynamicTokenRequest : BaseOAuthRequest
    {
        private string code; // 授权码，必填
        private string grantType;

        /// <summary>
        /// https://developer.meituan.com/docs/biz/comm-dev-isv-auth
        /// </summary>
        /// <param name="businessId">业务类型Id https://developer.meituan.com/docs/biz/comm-dev-isv-api-rule</param>
        /// <param name="code">授权码</param>
        public DynamicTokenRequest(int businessId, string code) : base(businessId)
        {
            this.code = code;
            this.grantType = "authorization_code";
        }

        public override Dictionary<String, object> toParams()
        {
            var pairs = new Dictionary<String, object>();
            pairs.Add(CommonConstants.BUSINESS_ID, BusinessId);
            if (!string.IsNullOrEmpty(code))
            {
                pairs.Add("code", code);
            }
            if (!string.IsNullOrEmpty(grantType))
            {
                pairs.Add("grantType", grantType);
            }
            return pairs;
        }
    }
}
